﻿using System;
using System.Web.UI.WebControls;
using AppCommon;
using Controller;

public partial class Modules_TourNoiBatControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataTourNB_Trongnuoc();
            BindDataTourNB_Docdao();
            BindDataTourNB_Nuocngoai();
            BindTintucNB();
            BindQuangCao02(Constants.QC2);
        }
    }

    public void BindDataTourNB_Trongnuoc()
    {
        var controllerTourTn = new VYC02Controller();
        var modelTourTn = controllerTourTn.GetByUniqueId(Common.ConvertToUnSign(Constants.TITLE_TOUR_TRONGNUOC));
        var controller = new VYC01Controller();
        var model = controller.GetTheoLoaiTour(modelTourTn[0].Id, 1);

        var pagedDataSource = new PagedDataSource();

        pagedDataSource.DataSource = model;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.PageSize = 9;
        pagedDataSource.CurrentPageIndex = 0;

        repeaterTourTN.DataSource = pagedDataSource;
        repeaterTourTN.DataBind();

    }
    public void BindDataTourNB_Docdao()
    {
        
        var controller = new VYC01Controller();
        var model = controller.GetTourDocDao(1);

        var pagedDataSource = new PagedDataSource();

        pagedDataSource.DataSource = model;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.PageSize = 9;
        pagedDataSource.CurrentPageIndex = 0;

        repeaterTourDd.DataSource = pagedDataSource;
        repeaterTourDd.DataBind();
    }

    public void BindDataTourNB_Nuocngoai()
    {
        var controllerTourTn = new VYC02Controller();
        var modelTourTn = controllerTourTn.GetByUniqueId(Common.ConvertToUnSign(Constants.TITLE_TOUR_NUOCNGOAI));
        var controller = new VYC01Controller();
        var model = controller.GetTheoLoaiTour(modelTourTn[0].Id, 1);

        var pagedDataSource = new PagedDataSource();

        pagedDataSource.DataSource = model;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.PageSize = 9;
        pagedDataSource.CurrentPageIndex = 0;

        repeaterTourNn.DataSource = pagedDataSource;
        repeaterTourNn.DataBind();
    }

    public void BindTintucNB()
    {
        var controller = new VYC06Controller();
        var model = controller.GetAllByView();

        var pagedDataSource = new PagedDataSource();

        pagedDataSource.DataSource = model;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.PageSize = 9;
        pagedDataSource.CurrentPageIndex = 0;

        repeaterTintuc.DataSource = pagedDataSource;
        repeaterTintuc.DataBind();
    }

    public void BindQuangCao02(string uniqueid)
    {
        var controller = new VYC05Controller();
        var model = controller.GetByUniqueId(uniqueid);

        // Get quang cao 1
        if (model.Count > 0)
        {
            var controller1 = new VYC06Controller();
            var model1 = controller1.GetBySubLoaiCm(model[0].Id, 1);

            // Set link and image
            if (model1.Count > 0)
            {
                linkQuangcao02.NavigateUrl = model1[0].LienKet;
                imgQuangcao02.ImageUrl = Constants.UPLOAD_TINTUC + model1[0].AnhDaiDien;
                imgQuangcao02.AlternateText = model1[0].TieuDe;
                imgQuangcao02.ToolTip = model1[0].TieuDe;
            }

        }
    }

    public int GetIdQuangcaoVYC1(int number)
    {
        var controller = new VYC05Controller();
        var model = controller.GetByUniqueId(Constants.SUB_QUANG_CAO + number);
        if (model.Count > 0)
            return model[0].Id;
        return 0;
    }
}